import { createPydFile } from '../../lib/files'
import { runPy } from '../../lib/runShell'
export default (req, res) => {
  /**
   * {
      username: '123123',
      keyword: 'cccc',
      rangeTime: [ '2022-04-06T16:00:08.454Z', '2022-04-07T03:54:01.254Z' ],
      cookie: 'scsadsadasd'
    }
   */
  const data = req.body
  createPydFile(data).then((newPath) => {
    console.log('RunTime data===>', data, newPath)
    if (newPath) {
      runPy(newPath)
      res.status(200).json({ ...data })
    } else {
      res.status(400).json({ ...data })
    }
  }).catch(err => {
    res.status(400).json({ err })
  })
}
